package com.derbysoft.lowcostadapter.commons.repository.impl;

import com.derbysoft.lowcostadapter.commons.model.Status;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

public class QueryHotelCondition {
    private String passport;

    private String name;

    private Integer propertyID;

    private Status status;

    public String getPassport() {
        return passport;
    }

    public void setPassport(String passport) {
        this.passport = StringUtils.trimToNull(passport);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = StringUtils.trimToNull(name);
    }

    public Integer getPropertyID() {
        return propertyID;
    }

    public void setPropertyID(Integer propertyID) {
        this.propertyID = propertyID;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(String status) {
        if (StringUtils.isBlank(status)) {
            return;
        }
        if (StringUtils.equals(status, "ENABLED")) {
            this.status = Status.ENABLED;
        } else {
            this.status = Status.DISABLED;
        }
    }

    public void appendToCriteria(DetachedCriteria criteria) {
        if (passport != null) {
            criteria.add(Restrictions.ilike("passport", passport, MatchMode.ANYWHERE));
        }

        if (name != null) {
            criteria.add(Restrictions.ilike("name", name, MatchMode.ANYWHERE));
        }

        if (propertyID != null) {
            criteria.add(Restrictions.eq("propertyID", propertyID));
        }

        if (status != null) {
            criteria.add(Restrictions.eq("status", status));
        }
    }
}
